const http = require('http')
const fs = require('fs')

const server = http.createServer()

server.on('request',(req,res)=>{
    //解决跨域问题
    res.writeHead(200,{
        "access-control-allow-origin":"*",
        "content-type":"text/plain;charset=utf-8"
    })

    fs.readFile('data/product.json',(err,data)=>{
        res.end(data)
    })
})

server.listen(3000,()=>{
    console.log('服务器创建成功！http://localhost:3000');
})